﻿@using ProjectManagement.Models
@using Projectmanagement.Entity
@{
    ViewBag.Title = "Project";
}
<style type="text/css">
    #Project
    {
        margin-top: 9px;
    }
</style>
@Html.Hidden("hideProjectID")
@(Html.Telerik().Grid<_Project>()
    .Name("Project")
    .DataKeys(keys => { keys.Add(item => item.ID); })
     .ToolBar(toolBar => toolBar.Template(
    @<text> 项目表： <a class="t-button t-grid-add" href="/Project?Project-mode=insert">新增记录</a>
</text>
     ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectIndex", "Project")
            .Insert("_InsertAjaxEditing", "Project")
            .Update("_SaveAjaxEditing", "Project");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.ProjectDisplayName).Width(140);
        columns.Bound(item => item.ProjectCode).Width(120);
        columns.Bound(item => item.Manager).Width(110);
        columns.Bound(item => item.TeamLeader).Width(110);
        columns.Bound(item => item.IsActived).Width(110);
        columns.Bound(item => item.StartDate).Width(110);
        columns.Bound(item => item.ConferenceStartDate).Width(110);
        columns.Bound(item => item.Target).Width(110);
        if (Employee.CurrentRoleLVL >= RoleLevel.Manager)
        {
            columns.Command(commands =>
            {
                commands.Edit();

            }).Title("操作").Width(100);
        }
    }).Resizable(r => r.Columns(true))

        .DetailView(viewParent => viewParent.ClientTemplate(
                Html.Telerik().TabStrip()
                    .Name("TabStrip_<#= ID #>")
                    .SelectedIndex(0)
                    .Items(itemsParent =>
                    {
                        itemsParent.Add().Text("里程碑").HtmlAttributes(new { style = "width:90px;text-align: center" }).Content(
                            Html.Telerik().Grid<_Milestone>()
                                .Name("Milestone_<#= ID #>")
                                .DataKeys(keys => { keys.Add(item => item.ID); })
                                .ClientEvents(events => events.OnEdit("onEdit"))
                                .ToolBar(toolBar => toolBar.Template(
                                    @<text> <a class="t-button t-grid-add" href="/Milestone?Milestone-mode=insert">新增记录</a>
<a class="t-button" href="javascript:void(0);" onclick=" GetMilestonePage('<#= ID #>') ">
    导入里程碑模板</a></text>
                                    ))
                                .DataBinding(dataBinding =>
                                {
                                    dataBinding.Ajax()
                                        .Select("_SelectIndexMilestone", "Milestone", new { conferenceid = "<#= ID #>" })
                                        .Insert("_InsertAjaxEditingMilestone", "Milestone", new { conferenceid = "<#= ID #>" })
                                        .Update("_SaveAjaxEditingMilestone", "Milestone", new { conferenceid = "<#= ID #>" });
                                })
                                .Columns(columns =>
                                {
                                    columns.Bound(item => item.MilestoneName).Width(240);
                                    columns.Bound(item => item.EndDate).Width(240);
                                    columns.Command(commands =>
                                    {
                                        commands.Edit();
                                    }).Title("操作").Width(200);
                                }).Resizable(r => r.Columns(true))
                                .DetailView(view => view.ClientTemplate(
                                    Html.Telerik().Grid<_Task>()
                                        .Name("Task_<#= Projectid #>_<#= ID #>")
                                        .DataKeys(keys => { keys.Add(item => item.ID); })
                                        .ClientEvents(events => events.OnEdit("onEdit"))
                                        .ToolBar(toolBar => toolBar.Template(
                                            @<text> <a class="t-button t-grid-add" href="/Task?Task-mode=insert" onclick="spid='<#= ID #>'">
                                                新增记录</a></text>
                                            ))
                                        .DataBinding(dataBinding =>
                                        {
                                            dataBinding.Ajax()
                                                .Select("_SelectIndexMilestone", "Task", new { MilestoneID = "<#= ID #>" })
                                                .Insert("_InsertAjaxIndexMilestone", "Task", new { MilestoneID = "<#= ID #>" });
                                        })
                                        .Columns(columns =>
                                        {
                                            columns.Bound(item => item.Name).Width(240);
                                            columns.Bound(item => item.StartDate).Width(140);
                                            columns.Bound(item => item.EndDate).Width(140);
                                            columns.Bound(item => item.Owners).Width(140);
                                            columns.Bound(item => item.Assinger).Width(120);
                                            columns.Bound(c => c.ID).ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>").Title("操作").Width(100);
                                        })
                                        .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                        .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true)).Scrollable(c => c.Height(300))
                                        .Sortable().ClientEvents(s => s.OnEdit("onEditTask")).Resizable(resizing => resizing.Columns(true)).ToHtmlString()))
                                .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true).PageSize(50))
                                .Scrollable(c => c.Height(353))
                                .Sortable()
                                .ToHtmlString()
                            );
                        itemsParent.Add().Text("成员").HtmlAttributes(new { style = "width:90px;text-align: center" }).Content(
                            Html.Telerik().Grid<_Member>()
                                .Name("Member_<#= ID #>")
                                .DataKeys(keys => { keys.Add(item => item.ID); })
                                .ToolBar(commands => commands.Insert())
                                .ClientEvents(events => events.OnEdit("onEditMember"))
                                .DataBinding(dataBinding =>
                                {
                                    dataBinding.Ajax()
                                        .Select("_SelectIndex", "Member", new { conferenceid = "<#= ID #>" })
                                        .Insert("_InsertAjaxEditing", "Member", new { conferenceid = "<#= ID #>" })
                                        .Update("_SaveAjaxEditing", "Member", new { conferenceid = "<#= ID #>" });
                                })
                                .Columns(columns =>
                                {
                                    columns.Bound(item => item.Name).Width(100);
                                    columns.Bound(item => item.RolePM).Width(100);
                                    columns.Bound(item => item.IsActivated).Width(100);
                                    columns.Bound(item => item.Description).Width(100);
                                    if (Employee.CurrentRoleLVL >= RoleLevel.Manager)
                                    {
                                        columns.Command(commands =>
                                        {
                                            commands.Edit();
                                        }).Title("操作").Width(100);
                                    }
                                })
                                .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true)).Scrollable(c => c.Height(353))
                                .Sortable().Resizable(resizing => resizing.Columns(true)).ToHtmlString());
                    })
                                    .ToHtmlString()
                            ))
            .Editable(editing => editing.Mode(GridEditMode.PopUp)).Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true).PageSize(50))
            .Scrollable(c => c.Height(570)).Sortable().Resizable(resizing => resizing.Columns(true))
        )
@(Html.Telerik().Window()
    .Name("ImpTaskTpl")
    .Content(@<text>
<div class="dialogue-impTaskTpl">
    <div class="impTaskTpl-wrapper">
    </div>
</div></text>)
    .Width(1000)
    .Height(350).Title("导入任务模板")
    .Modal(true).Visible(false).Draggable(true)
)
@(Html.Telerik().Window()
        .Name("ImpMilestoneTpl")
    .Content(@<text>
<div class="dialogue-impMilestoneTpl">
    <div class="impMilestoneTpl-wrapper">
    </div>
</div></text>)
    .Width(1000)
    .Height(350).Title("导入里程碑模板")
    .Modal(true).Visible(false).Draggable(true)
)
<script type="text/javascript">
    var spid = "";

    function GetITTPage(currentProjectId) {
        $.post('/Project/GetImpTaskTpl', { projectId: currentProjectId }, function (result) {
            $('.impTaskTpl-wrapper').html(result);
            var window = $('#ImpTaskTpl').data('tWindow');
            window.center().open();
        });
    }

    function GetMilestonePage(currentProjectId) {
        $.post('/Project/GetImpMilestoneTpl', { projectId: currentProjectId }, function (result) {
            $('.impMilestoneTpl-wrapper').html(result);
            var window = $('#ImpMilestoneTpl').data('tWindow');
            window.center().open();
        });
    }

    $('#search-project').click(function () {
        $("#Project").data("tGrid").ajaxRequest();
    });
    function onEdit(e) {
        var taskId = e.dataItem["ID"];
        if (taskId == 0) {
            $("#comment").hide();
            $("input[name=Owners]").hide();
            $("input[name=Owners]").after($("input[name=Owners]").val());
            //            $("select[name=ProjectID]").val(spid).hide();
            //            $("select[name=ProjectID]").after($("select[name=ProjectID] option:selected").text());
        } else {
            $("#legendTitle").html("编辑任务");
            $("input[name=Owners]").hide();
            $("input[name=Owners]").after($("input[name=Owners]").val());
            $("#Name").attr("disabled", "disabled");
            $("#TaskStateID").attr("disabled", "disabled");
            $("select[name=ProjectID]").hide();
            $("select[name=ProjectID]").after($("select[name=ProjectID] option:selected").text());
            $.post('/Task/GetCommentList', { taskid: taskId }, function (result) {
                $('#commentList').html(result);
            });
        }
    }

    function onEditMember(e) {
        var taskId = e.dataItem["ID"];
        if (taskId != 0) {
            $("#Name").attr("disabled", "disabled");
        }
    }

    function onEditTask(e) {
        var id = e.target.id.substring(5);
        $("#ProjectID option[value=" + id + "]").attr("selected", true);
        $("#hideProjectID").val(id);
    }
</script>
<script>
    function showtask(id) {
        $.post('Task/GetDetail/', { taskid: id }, function (result) {
            $('.TastMessage-wrapper').html(result);
            var window = $('#TastMessage').data('tWindow');
            window.center().open();
        });
    }

    function dtonChange(e) {
        $("form").submit();
    }

    function getmembers() {
        var id = $("#hideProjectID").val();
        if (id == "") {
            alert("请先选择一个项目");
            return;
        }
        $.post('/Member/getmembers', { projectId: id }, function (result) {
            $('.GetMembers-wrapper').html(result);
            var window = $('#GetMembers').data('tWindow');
            window.center().open();
        });
    }
    function pubProjectID(e) {
        $("#hideProjectID").val(e);
    }
</script>
@(Html.Telerik().Window().Title("任务信息")
    .Name("TastMessage")
    .Content(@<text><div class="dialogue-TastMessage">
        <div class="TastMessage-wrapper">
        </div>
    </div></text>)
    .Width(1050)
    .Height(550)
    .Modal(true).Visible(false).Draggable(true)
)